use std::panic::{self, catch_unwind};

use axum_app_common::model::BizResponse;
use futures::FutureExt;
use serde_json::Value;

async fn async_function() -> BizResponse<Value> {
    // 在这里编写可能会抛出 panic 的代码
    panic!("An error occurred in the async function.");
}

#[tokio::test]
async fn test() {
    println!("================");
    let future = Box::pin(async_function());

    let res = future.catch_unwind().await;

    println!("res: {:?}", res);

    match res {
        Ok(r) => println!("{r:?}"),
        Err(err) => {
            println!("type_id: {:?}", err.type_id());
        }
    }
}
